﻿using System;
using System.Collections.Generic;
using System.Text;
using curbside.Web.UI.WebControls;

namespace curbside.Web.UI.Script
{
    public class PageClientScript
    {
        /// <summary>
        /// 弹出alert对话框
        /// </summary>
        /// <param name="msg"></param>
        public static void Prompt(string msg)
        {
            string jsEventCode = "$(function(){alert('" + msg + "')});";
            helper.AddStartupScript("Prompt", jsEventCode);
        }

        /// <summary>
        /// 打开新窗口
        /// </summary>
        /// <param name="url"></param>
        public static void OpenNewWindow(string url)
        {
            string jsEventCode = "$(function(){window.open('" + url + "','_blank')});";
            helper.AddStartupScript("OpenNewWindow", jsEventCode);
        }

        /// <summary>
        /// 提示，并跳转到目标页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void PromptAndRedirect(string msg, string url)
        {
            string jsEventCode = "$(function(){alert('" + msg + "');window.open('" + url + "','_self')});";
            helper.AddStartupScript("PromptAndRedirect", jsEventCode);
        }

        public static void Prompt(string msg, bool autoClose)
        {
            string jsEventCode = "$(function(){window.dialog('" + msg + "'," + autoClose.ToString().ToLower() + ")});";
            helper.AddStartupScript("dialog", jsEventCode);
        }

        public static void Prompt(string msg, bool autoClose, int count)
        {
            string jsEventCode = "$(function(){window.dialog('" + msg + "'," + autoClose.ToString().ToLower() + ", " + count + ")});";
            helper.AddStartupScript("dialog", jsEventCode);
        }

        public static void EnableAjaxPro(Type type)
        {
            AjaxPro.Utility.RegisterTypeForAjax(type);
        }
    }
}
